//搜索相关
function mapSearcher () {
	this.keyword = '银行';
	this.centerKeyword = '';
	this.citycode = '';
	this.cityname = '杭州';
	this.resultPane = 'search_result_content';
	this.searchType = 'keyword';	//keyword and centerKeyword
	
	/*搜索结果相关*/
	this.searchResultShowInner = false;
	this.searchResultInner = '';
	this.reaultTag = 'yh';
	this.searchResultCount = 10;
}

mapSearcher.prototype = {
	
	/*搜索结果显示、显示搜索结果面板*/
	showSearchResultPane : function(){
		if (this.searchResultShowInner) {
			var searchResult = document.getElementById(this.resultPane);
			if (searchResult != null && searchResult != 'undefined' ) {
				searchResult.innerHTML = mapSearcherObj.searchResultInner;
			}
		}
	},
	
	/*搜索相关方法*/
	searchPointBykeywords : function(){
		var mls =new MLocalSearch();  
		var mlsp= new MLocalSearchOptions();
		mlsp.recordsPerPage = this.searchResultCount;
		mls.setCallbackFunction(this.showSearchResultList);
		if (this.searchType == 'keyword') {
			mls.poiSearchByKeywords(this.keyword, this.citycode, mlsp);  
		} else {
			if (this.centerKeyword == '' || this.centerKeyword == null || this.centerKeyword == 'undefined') {
				alert('中心点关键词不能为空');
			}else{
				mls.poiSearchByCenterKeywords(this.centerKeyword,this.keyword,this.citycode,mlsp);
			}
		}
	},
	
	showSearchResultList1 : function(data){
		var temp = "";
		var overarr = new Array();
		for(var i=0; i<data.length; i++) {
			if (data[i]['x'] != null && data[i]['y'] != null) {
				var x = data[i]['x'];
				var y = data[i]['y'];
				var sContent = getPointTipContents(data[i]['saletele'],data[i]['aveprice'],data[i]['address'],data[i]['hid']); //htmlDecode(data[i]['laber']);
				mapPointObj = new mapPoint();
				var pointId = (i+1); 
				mapPointObj.point_x = x;
				mapPointObj.point_y = y;
				mapPointObj.pointTitle = i + 1 +" "+ data[i]['name'];
				mapPointObj.pointTip = sContent;
				mapPointObj.pointId = pointId;
				mapPointObj.showTip = 'hid';
				mapPointObj.showPointDelay = true;
				mapPointObj.pointImageURL = "http://code.mapabc.com/images/apin/lan_"+(i+1)+".png";
				mapPointObj.showLaber = true;
				mapPointObj.pointLaber = i + 1 +" "+ data[i]['name'];
				drawPointOnMap(mapPointObj);
				overarr.push(marker);
				
				//addLabel(data[i]['name'],x,y);
				
				temp += "<li onmouseover='panToCenter("+x+","+y+","+pointId+")' class=\"item\" id="+pointId+" >";
				temp += "<h4 onclick='panToCenter("+x+","+y+"),showMapPointTip("+ pointId +")' style=\"cursor:pointer;\">"+ data[i]['name'] +"</h4>";
				temp += "<ul class=\"attr\"><li>电话："+ data[i]['saletele'] +"</li>";
				temp += "<li>均价："+data[i]['aveprice']+"元/M2</li>";
				temp += "<li>地址："+data[i]['address']+"</li>";
				temp += "<li><a href='index.php?m=house&q=info&hid="+data[i]['hid']+"' target='_blank'>详情页</a></li></ul>";
				temp += "</li>";
			}else{
				temp += "<li class=\"item\" >";
				temp += "<h4 style=\"cursor:pointer;\">"+ data[i]['name'] +"</h4>";
				temp += "<ul class=\"attr\"><li style='color: rgb(137, 137, 137)'>未在地图上标注该楼盘</li>";
				temp += "<li>电话："+ data[i]['saletele'] +"</li>";
				temp += "<li>均价："+data[i]['aveprice']+"元/M2</li>";
				temp += "<li>地址："+data[i]['address']+"</li>";
				temp += "<li><a href='index.php?m=house&q=info&hid="+data[i]['hid']+"' target='_blank'>详情页</a></li></ul>";
				temp += "</li>";
			}
		}
		mapObj.addOverlays(overarr,true);
		this.searchResultInner = temp;
		this.showSearchResultPane();
	},
	
	/*搜索结果显示、在地图上描点*/
	showSearchResultList : function(data){
		var temp = "";
		var overarr = new Array();
		for (var i=0; i < data.poilist.length; i++) {
			var x = data.poilist[i].x;
			var y = data.poilist[i].y;
			var type = data.poilist[i].type;
			if (type == "" || type == "undefined" || type == null) {
				type == "暂无";
			}
			var address = data.poilist[i].address;
			if (address == "" || address == "undefined" || address == null) {
				address = "暂无";				
			}
			var tel = data.poilist[i].tel;
			if (tel == "" || tel == "undefined" || tel == null) {
				tel = "暂无";
			}
			var sContent = "";
			sContent += "<br><font color='#000'>类型:"+type+"</font><br />";
			sContent += "<font color='#000'>地址:"+address+"</font><br />";
			sContent += "<font color='#000'>电话:"+tel+"</font><br />";
			
			mapPointObj = new mapPoint();
			var pointId = (i + 1);
			if (searchPointsTag != '' && searchPointsTag != 'undefined' && searchPointsTag != null) {
				pointId = searchPointsTag + "_" + (i + 1); 
			}
			mapPointObj.point_x = x;
			mapPointObj.point_y = y;
			mapPointObj.pointTitle = i + 1 + " " + data.poilist[i].name;
			mapPointObj.pointTip = sContent;
			mapPointObj.pointId = pointId;
			mapPointObj.showTip = 'hid';
			mapPointObj.showPointDelay = true;
			mapPointObj.pointImageURL = "http://code.mapabc.com/images/apin/lan_"+(i+1)+".png";
			drawPointOnMap(mapPointObj);
			overarr.push(marker);
			
			temp += "<li class=\"item \" id="+pointId+" onclick='showMapPointTip("+ pointId +")' >";
			temp += "<dl><dt>"+ (i+1)+": "+data.poilist[i].name +"</dt>";
			temp += "<dd>电话："+ data.poilist[i].tel +"</dd>";
			temp += "<dd>地址："+ data.poilist[i].address +"</dd>";
			temp += "<dd>城市："+ data.poilist[i].citycode +"</dd>";
			temp += "<dd>类型："+ data.poilist[i].type +"</dd>";
			temp += "</li>";
		}
		mapObj.addOverlays(overarr,true);
		mapSearcherObj.searchResultInner = temp;
		mapSearcherObj.showSearchResultPane();
	},
	
	/*清理搜索结果*/
	clearSearchResult : function(tag){
		var arr = mapObj.getOverlaysByType(MOverlay.TYPE_MARKER);
		for(var i = 0; i < arr.length; i++){
			var markerObjId = arr[i].id;
			if(markerObjId.match(tag)){
				mapObj.removeOverlay(arr[i]);
			}
		}
	}
}
var mapSearcherObj = new mapSearcher();